package com.polaris.live.adapter

import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.SpanUtils
import com.blankj.utilcode.util.StringUtils
import com.bumptech.glide.Glide
import com.polaris.live.R
import com.polaris.live.common.R.drawable
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterPartyTaskBinding
import com.polaris.live.resp.back_resp.UserTaskVo
import com.polaris.live.translation.R.string
import com.polaris.live.utils.image.ImageUtils

/**
 * PartyTaskAdapter
 *
 * @author Created by 半仙 on 2024/2/28/028 15:43
 */
class PartyTaskAdapter : BaseBindingAdapter<AdapterPartyTaskBinding, UserTaskVo>() {

    init {
        addChildClickViewIds(R.id.go_to_router)
    }

    override fun convert(holder: VBViewHolder<AdapterPartyTaskBinding>, item: UserTaskVo) {
        holder.vb.apply {
            tvContent.text = item.content
            val getColor = if (item.taskCurrent == 0L) {
                ColorUtils.getColor(R.color.color_ffffff_30)
            } else {
                ColorUtils.getColor(R.color.white)
            }
            if (item.completed) {
                goToRouter.setBackgroundResource(R.drawable.r26_back_fff_10)
                goToRouter.text = StringUtils.getString(string.ps_completed)
            } else {
                goToRouter.setBackgroundResource(drawable.r26_radient)
                goToRouter.text = StringUtils.getString(string.go_to_finish)
            }
            val span = SpanUtils.with(taskProgress)
                .append("${item.taskCurrent}")
                .setForegroundColor(getColor)
                .append("/${item.taskTotal}")
                .setForegroundColor(ColorUtils.getColor(R.color.color_ffffff_30))
                .create()
            taskProgress.text = span
            Glide.with(context).load(ImageUtils.imgPath(item.rewardPhotoUrl)).into(itemDetailImg)
            Glide.with(context).load(ImageUtils.imgPath(item.photoUrl)).into(itemImg)
            tvRewardCount.text = item.rewardContent

            if (item.coinTask) {
                ivBeans.visibility = View.VISIBLE
            } else {
                ivBeans.visibility = View.GONE
            }
        }
    }

}